﻿#region Imports
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Messages;
using CommonUtilities.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endregion

namespace CommonUtilities.UnitTest.UTExtensions
{
    [TestClass]
    public class CollectionExtensions_Test
    {
        [TestMethod]
        public void OrderByProperty_Test()
        {
            string sBasePath = Environment.SpecialFolder.MyPictures.GetFolderPath();
            ObservableCollection<string> files
                = new ObservableCollection<string>(Directory.GetFiles(sBasePath));
            ObservableCollection<FileInfo> allFileInfo = new ObservableCollection<FileInfo>();

            if (files.LongCount() > 0)
                files.ToList().ForEach(file => allFileInfo.Add(new FileInfo(file)));

            string fields = "Name,Length,Extension,DirectoryName,CreationTime";
            foreach (string prop in fields.Split(','))
            {
                string sFiles = "";
                allFileInfo.OrderByProperty(prop, eSortDirection.Ascending).ForEach(file =>
                    sFiles += file.GetType().GetProperty(prop).GetValue(file, null).ToString() + Utilities.cNewLine);

                MessageBoxUtil.Show(false, sFiles, "Sort :: " + prop);
            }
        }
    }
}
